package Sagittarius.Component
{
	import flash.geom.Point;
	import Sagittarius.VO.TrackVO;
	
	import com.pblabs.engine.components.TickedComponent;
	import com.pblabs.engine.entity.PropertyReference;
	
	import Sagittarius.Manager.*;
	
	/**
	 * ...
	 * @author Aqua
	 */
	public class MoveOnTrackComponent extends TickedComponent
	{
		
		//---------------------//
		//     Constructor     //
		//---------------------//
		
		/**************************************************************************
		 * function				MoveOnTrackComponent
		 * description			constructor
		 *************************************************************************/
		public function MoveOnTrackComponent():void
		{
			super();
		}
		
		//-----------------//
		//     Publics     //
		//-----------------//
		
		/**************************************************************************
		 * function				onTick
		 * description			change owner's position by frames
		 * @param	deltaTime	time passed from last frame
		 *************************************************************************/
		public override function onTick(deltaTime:Number):void
		{
			var newPos:Point;
			var deltaPos:Point;
			var vo:TrackVO;
			var frame:int;
			
			super.onTick(deltaTime);
			
			frame = GameManager.instance.currentFrame - _startFrame;
			vo = ObjectManager.instance.getObj(trackId);
			deltaPos = vo.posPerFrames[frame];
			newPos = new Point(startPos.x + deltaPos.x, _startPos.y + deltaPos.y);
			
			this.owner.setProperty(_positionProperty, newPos);
		}
		
		public var _positionProperty	:PropertyReference;
		public var _startFrame			:int;
		public var _startPos			:Point;
		public var _trackId				:String;
	}
	
}